package com.rickpan.repository;

import com.rickpan.entity.ChatSession;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 聊天会话Repository
 */
@Repository
public interface ChatSessionRepository extends JpaRepository<ChatSession, Long> {
    
    /**
     * 根据用户ID查找会话，按更新时间倒序
     */
    List<ChatSession> findByUserIdOrderByUpdatedAtDesc(Long userId, Pageable pageable);
    
    /**
     * 根据ID和用户ID查找会话
     */
    ChatSession findByIdAndUserId(Long id, Long userId);
    
    /**
     * 统计用户的会话数量
     */
    long countByUserId(Long userId);
}
